package com.model;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Arrays;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;


@Entity
@Table(name = "evento_photo")
/*@NamedQueries({
    @NamedQuery(name = "EventoFoto.findAll", query = "SELECT e FROM EventoFoto e"),
    @NamedQuery(name = "EventoFoto.findByPhotoId", query = "SELECT e FROM EventoFoto e WHERE e.photoId = :photoId")})
*/public class EventoFoto implements Serializable {
	
	private static final long serialVersionUID = 1L;
    
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    
    @Column(name = "photo_id")
    private Integer photoId;
    @Column(name = "photo_name")
    private String photoName;
    @Lob
    @Column(name = "photo_data")
    private byte[] photoData;
    
    @Transient
    private StreamedContent imagem;
    
    
    
    public StreamedContent getImage() {
    	InputStream is = new ByteArrayInputStream(getPhotoData());  
	    this.imagem = new DefaultStreamedContent(is, "image/png", "fileName.png");
		return this.imagem;
	}
	public void setImage(StreamedContent image) {
		this.imagem = image;
	}
	private Integer photo_idFK;
	
    public EventoFoto() {
    }
    public EventoFoto (Integer photoId) {
        this.photoId = photoId;
    }

    public Integer getPhotoId() {
        return photoId;
    }

    public void setPhotoId(Integer photoId) {
        this.photoId = photoId;
    }

    public String getPhotoName() {
        return photoName;
    }

    public void setPhotoName(String photoName) {
        this.photoName = photoName;
    }

    public byte[] getPhotoData() {
    	    	return photoData;
    }

    public void setPhotoData(byte[] photoData) {
        this.photoData = photoData;
    }
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(photoData);
		result = prime * result + ((photoId == null) ? 0 : photoId.hashCode());
		result = prime * result
				+ ((photoName == null) ? 0 : photoName.hashCode());
		result = prime * result
				+ ((photo_idFK == null) ? 0 : photo_idFK.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EventoFoto other = (EventoFoto) obj;
		if (!Arrays.equals(photoData, other.photoData))
			return false;
		if (photoId == null) {
			if (other.photoId != null)
				return false;
		} else if (!photoId.equals(other.photoId))
			return false;
		if (photoName == null) {
			if (other.photoName != null)
				return false;
		} else if (!photoName.equals(other.photoName))
			return false;
		if (photo_idFK == null) {
			if (other.photo_idFK != null)
				return false;
		} else if (!photo_idFK.equals(other.photo_idFK))
			return false;
		return true;
	}

    
    

	
    
}
